import java.util.*;

public class LeetCode1207 {
    public static void main(String[] args) {
        System.out.println(uniqueOccurrences1(new int[]{1,2,2,1,1,3}));
        System.out.println(uniqueOccurrences1(new int[]{1,2}));
        System.out.println(uniqueOccurrences1(new int[]{-3,0,1,-3,1,1,1,-3,10,0}));
        String s1;
        String s2;

    }

    public static boolean uniqueOccurrences(int[] arr) {
        HashSet<Integer> sets = new HashSet<>(arr.length);
        for(int num: arr){
            sets.add(num);
        }

        int length = sets.size();
        ArrayList<Integer> size = new ArrayList<Integer>(length);
        for(int i = 0; i < length; i++){
            size.add(0);
        }

        ArrayList<Integer> setList = new ArrayList<>(sets);
        for(int k = 0; k < arr.length; k++){
            int index = setList.indexOf(arr[k]);
            int old = size.get(index);
            size.set(index, ++old);
        }

        HashSet sizeSet = new HashSet(length);
        for (int num: size){
            sizeSet.add(num);
        }

        if(length == sizeSet.size()){
            return true;
        }

        return false;
    }

    public static boolean uniqueOccurrences1(int[] arr) {
        Map<Integer, Integer> occur = new HashMap<Integer, Integer>(arr.length);
        for (int x : arr) {
            occur.put(x, occur.getOrDefault(x, 0) + 1);
        }
        Set<Integer> times = new HashSet<Integer>(occur.size());
        for (Map.Entry<Integer, Integer> x : occur.entrySet()) {
            times.add(x.getValue());
        }
        return times.size() == occur.size();

    }
}
